package suanfa;

import org.junit.Test;

public class ReverseTest
{
    public int reverse(int x)
    {
        try
        {
            String s = String.valueOf(x);
            String len = "";
            StringBuilder last = new StringBuilder();
            if (s.indexOf("-") == 0)
            {
                len = s.substring(1);
                last.append("-");
            }
            else
            {
                len = s;
            }
            char[] chars = len.toCharArray();
            for (int i = chars.length - 1; i >= 0; i--)
            {
                last.append(chars[i]);
            }
            return Integer.parseInt(last.toString());
        }
        catch (Exception e)
        {
            return 0;
        }

    }

    @Test
    public void test()
    {
        int reverse = reverse(-123);
        System.out.println(reverse);
        System.out.println(Integer.MAX_VALUE +  "==="+Integer.MIN_VALUE);
    }
}
